$(function () {
    findById();
});

function findById() {
    let id = sessionStorage.getItem("dailyId");
    let result = myAjax("/api/dw/daily/findById", {id: id}, "post");
    if (result != null) {
        setData(result.data);
    }
}

function setData(data) {
    $("#author").val(data.author);
    $("#time").val(data.time);
    $("#major").val(data.major);
    $("#coach").val(data.coach);
    $("#councilor").val(data.councilor);
    $("#content").val(data.content);
    $("#event").val(data.event);
    $("#starred").val(data.starred);
    $("#harvest").val(data.harvest);
    $("#doubt").val(data.doubt);
    $("#help").val(data.help);
}

function save() {
    let data = {
        id: sessionStorage.getItem("dailyId"),
        userId: sessionStorage.getItem("userId"),
        author: $("#author").val(),
        time: $("#time").val(),
        major: $("#major").val(),
        coach: $("#coach").val(),
        councilor: $("#councilor").val(),
        content: $("#content").val(),
        event: $("#event").val(),
        starred: $("#starred").val(),
        harvest: $("#harvest").val(),
        doubt: $("#doubt").val(),
        help: $("#help").val()
    };
    let result = myAjax("/api/dw/daily/update", data, "post");
    if (result.data === 1) {
        layer.alert("更新成功", {icon: 1});
        x_admin_close();
        x_admin_father_reload();
    }
    layer.alert("更新失败", {icon: 2});
}